
import email from './email'

const directives = {
  email
}

const xql = {
  // 插件集合
  useList: [],
  use(useList) {
    if(!useList || !Array.isArray(useList)) {
      console.warn('你注册指令的方式不对. 请传入一个数组或者不使用use按需注册')
      return
    }

    this.useList = useList
  },
  install(Vue) {
    if(this.useList.length === 0 ) {
      // 全部注册
      this.useList = Object.keys(directives)
    }

    this.useList.forEach(item => {
      if( Object.prototype.hasOwnProperty.call(directives, item)) {
        Vue.directive(item, directives[item])
      } else {
        throw new Error('不存在指令--', item)
      }
    })
  }
}

export default xql